//
//  XMLHome.swift
//  Weibo
//
//  Created by mac on 16/5/13.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class XMLHome: NSObject {

    var created_at :String?
    var id :Int64 = 0
    var text :String?
    var source :String?
    var user :XMLUserInfo?
    var retweeted_status :XMLHome?
    ///  转发数
    var reposts_count: Int = 0
    ///  评论数
    var comments_count: Int = 0
    ///  表态数
    var attitudes_count: Int = 0
    /// 转发图片
    var pic_urls :[XMLHomePic]?

    
    init(dict :[String :AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
        
            guard let dict = value as? [String :AnyObject] else {
            
                return
            }
            user = XMLUserInfo(dict: dict)
        }else if key == "retweeted_status" {
            guard let dict = value as? [String :AnyObject] else {
                
                return
            }
            retweeted_status = XMLHome(dict: dict)
            
        }else if key == "pic_urls"{
            guard let dictArray = value as? [[String :AnyObject]] else {
            
                return
            }
            var nmArray = [XMLHomePic]()
            for dict in dictArray {
                let homePic = XMLHomePic(dict: dict)
                nmArray.append(homePic)
            }
            pic_urls = nmArray
            
        
            
        }else {
        
            super.setValue(value, forKey: key)
        }
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
}

